<template>
	<view class="" v-if="show" :class="ggclass" @click="$emit('click',$event)">
		<slot v-bind="slotData"></slot>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex'
	import {
		dateFilter
	} from '../ways/filter.js'
	export default {
		name: 'c-is-show',
		inject: {
			parent: {
				default: ''
			}
		},
		props: {
			auths: {
				type: Array,
				default: () => [1]
			},
			name: {
				type: String,
				default: ''
			},
			api: {
				type: String,
				default: ''
			},
			rangeKey: {
				type: String,
				default: 'result'
			},
			ggclass: {
				type: String,
				default: ''
			},
			params: {
				type: Object,
				default: () => {
					return {}
				}
			},
			range_key: {
				type: String,
				default: 'userType'
			}
		},
		data() {
			return {
				slotData: {},
			}
		},
		computed: {
			...mapState(['userInfo']),
			show() {
				let userType = this.userInfo[this.range_key] || 0
				let boo = (this.auths||[]).includes(userType)
				// let boo = (this.auths || []).includes(1)
				if (boo && this.api) {
					let req = typeof this.api === 'function' ? this.api.bind(this, this.params) : this.$http.get.bind(this
						.$http,
						this.api, this.params)
					req().then((res) => {
						this.slotData = res[this.rangeKey] || {}
						this.$emit('input', this.slotData)
					})
				}
				return boo
			}
		}

	}
</script>

<style scoped>
</style>